
package technical_engineering.gui;

import technical_engineering.procedures.SafetyConditionProcedure;
import technical_engineering.procedures.RedstoneLowConditionProcedure;
import technical_engineering.procedures.RedstoneHighConditionProcedure;
import technical_engineering.procedures.InfoConditionProcedure;
import technical_engineering.procedures.FuelCondition6Procedure;
import technical_engineering.procedures.FuelCondition5Procedure;
import technical_engineering.procedures.FuelCondition4Procedure;
import technical_engineering.procedures.FuelCondition3Procedure;
import technical_engineering.procedures.FuelCondition2Procedure;
import technical_engineering.procedures.FuelCondition1Procedure;
import technical_engineering.procedures.EnergyCondition9Procedure;
import technical_engineering.procedures.EnergyCondition8Procedure;
import technical_engineering.procedures.EnergyCondition7Procedure;
import technical_engineering.procedures.EnergyCondition6Procedure;
import technical_engineering.procedures.EnergyCondition5Procedure;
import technical_engineering.procedures.EnergyCondition4Procedure;
import technical_engineering.procedures.EnergyCondition3Procedure;
import technical_engineering.procedures.EnergyCondition2Procedure;
import technical_engineering.procedures.EnergyCondition1Procedure;
import technical_engineering.procedures.EnergyCondition11Procedure;
import technical_engineering.procedures.EnergyCondition10Procedure;
import technical_engineering.procedures.AdvanceCondition9Procedure;
import technical_engineering.procedures.AdvanceCondition8Procedure;
import technical_engineering.procedures.AdvanceCondition7Procedure;
import technical_engineering.procedures.AdvanceCondition6Procedure;
import technical_engineering.procedures.AdvanceCondition5Procedure;
import technical_engineering.procedures.AdvanceCondition4Procedure;
import technical_engineering.procedures.AdvanceCondition3Procedure;
import technical_engineering.procedures.AdvanceCondition2Procedure;
import technical_engineering.procedures.AdvanceCondition1Procedure;
import technical_engineering.procedures.AdvanceCondition11Procedure;
import technical_engineering.procedures.AdvanceCondition10Procedure;

import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.api.distmarker.Dist;

import net.minecraft.world.World;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.ResourceLocation;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.Minecraft;

import java.util.HashMap;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.matrix.MatrixStack;

import com.google.common.collect.ImmutableMap;

@OnlyIn(Dist.CLIENT)
public class MachineCrusherGuiWindow extends ContainerScreen<MachineCrusherGui.GuiContainerMod> {
	private World world;
	private int x, y, z;
	private PlayerEntity entity;
	private final static HashMap guistate = MachineCrusherGui.guistate;
	public MachineCrusherGuiWindow(MachineCrusherGui.GuiContainerMod container, PlayerInventory inventory, ITextComponent text) {
		super(container, inventory, text);
		this.world = container.world;
		this.x = container.x;
		this.y = container.y;
		this.z = container.z;
		this.entity = container.entity;
		this.xSize = 176;
		this.ySize = 166;
	}
	private static final ResourceLocation texture = new ResourceLocation("technical_engineering:textures/machine_crusher.png");
	@Override
	public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
		this.renderBackground(ms);
		super.render(ms, mouseX, mouseY, partialTicks);
		this.renderHoveredTooltip(ms, mouseX, mouseY);
	}

	@Override
	protected void drawGuiContainerBackgroundLayer(MatrixStack ms, float partialTicks, int gx, int gy) {
		RenderSystem.color4f(1, 1, 1, 1);
		RenderSystem.enableBlend();
		RenderSystem.defaultBlendFunc();
		Minecraft.getInstance().getTextureManager().bindTexture(texture);
		int k = (this.width - this.xSize) / 2;
		int l = (this.height - this.ySize) / 2;
		this.blit(ms, k, l, 0, 0, this.xSize, this.ySize, this.xSize, this.ySize);
		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/energy_0.png"));
		this.blit(ms, this.guiLeft + 9, this.guiTop + 10, 0, 0, 13, 46, 13, 46);
		if (EnergyCondition1Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/energy_1.png"));
			this.blit(ms, this.guiLeft + 9, this.guiTop + 10, 0, 0, 13, 46, 13, 46);
		}
		if (EnergyCondition2Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/energy_2.png"));
			this.blit(ms, this.guiLeft + 9, this.guiTop + 10, 0, 0, 13, 46, 13, 46);
		}
		if (EnergyCondition3Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/energy_3.png"));
			this.blit(ms, this.guiLeft + 9, this.guiTop + 10, 0, 0, 13, 46, 13, 46);
		}
		if (EnergyCondition4Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/energy_4.png"));
			this.blit(ms, this.guiLeft + 9, this.guiTop + 10, 0, 0, 13, 46, 13, 46);
		}
		if (EnergyCondition5Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/energy_5.png"));
			this.blit(ms, this.guiLeft + 9, this.guiTop + 10, 0, 0, 13, 46, 13, 46);
		}
		if (EnergyCondition6Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/energy_6.png"));
			this.blit(ms, this.guiLeft + 9, this.guiTop + 10, 0, 0, 13, 46, 13, 46);
		}
		if (EnergyCondition7Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/energy_7.png"));
			this.blit(ms, this.guiLeft + 9, this.guiTop + 10, 0, 0, 13, 46, 13, 46);
		}
		if (EnergyCondition8Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/energy_8.png"));
			this.blit(ms, this.guiLeft + 9, this.guiTop + 10, 0, 0, 13, 46, 13, 46);
		}
		if (EnergyCondition9Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/energy_9.png"));
			this.blit(ms, this.guiLeft + 9, this.guiTop + 10, 0, 0, 13, 46, 13, 46);
		}
		if (EnergyCondition10Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/energy_10.png"));
			this.blit(ms, this.guiLeft + 9, this.guiTop + 10, 0, 0, 13, 46, 13, 46);
		}
		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/thermal.png"));
		this.blit(ms, this.guiLeft + 47, this.guiTop + 52, 0, 0, 16, 16, 16, 16);
		if (FuelCondition6Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/thermal_5.png"));
			this.blit(ms, this.guiLeft + 47, this.guiTop + 52, 0, 0, 16, 16, 16, 16);
		}
		if (FuelCondition5Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/thermal_4.png"));
			this.blit(ms, this.guiLeft + 47, this.guiTop + 52, 0, 0, 16, 16, 16, 16);
		}
		if (FuelCondition4Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/thermal_3.png"));
			this.blit(ms, this.guiLeft + 47, this.guiTop + 52, 0, 0, 16, 16, 16, 16);
		}
		if (FuelCondition3Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/thermal_2.png"));
			this.blit(ms, this.guiLeft + 47, this.guiTop + 52, 0, 0, 16, 16, 16, 16);
		}
		if (FuelCondition2Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/thermal_1.png"));
			this.blit(ms, this.guiLeft + 47, this.guiTop + 52, 0, 0, 16, 16, 16, 16);
		}
		if (FuelCondition1Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/thermal_0.png"));
			this.blit(ms, this.guiLeft + 47, this.guiTop + 52, 0, 0, 16, 16, 16, 16);
		}
		if (EnergyCondition11Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/energy_11.png"));
			this.blit(ms, this.guiLeft + 9, this.guiTop + 10, 0, 0, 13, 46, 13, 46);
		}
		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/advance_0.png"));
		this.blit(ms, this.guiLeft + 78, this.guiTop + 27, 0, 0, 24, 24, 24, 24);
		if (AdvanceCondition1Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/advance_1.png"));
			this.blit(ms, this.guiLeft + 78, this.guiTop + 27, 0, 0, 24, 24, 24, 24);
		}
		if (AdvanceCondition2Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/advance_2.png"));
			this.blit(ms, this.guiLeft + 78, this.guiTop + 27, 0, 0, 24, 24, 24, 24);
		}
		if (AdvanceCondition3Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/advance_3.png"));
			this.blit(ms, this.guiLeft + 78, this.guiTop + 27, 0, 0, 24, 24, 24, 24);
		}
		if (AdvanceCondition4Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/advance_4.png"));
			this.blit(ms, this.guiLeft + 78, this.guiTop + 27, 0, 0, 24, 24, 24, 24);
		}
		if (AdvanceCondition5Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/advance_5.png"));
			this.blit(ms, this.guiLeft + 78, this.guiTop + 27, 0, 0, 24, 24, 24, 24);
		}
		if (AdvanceCondition6Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/advance_6.png"));
			this.blit(ms, this.guiLeft + 78, this.guiTop + 27, 0, 0, 24, 24, 24, 24);
		}
		if (AdvanceCondition7Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/advance_7.png"));
			this.blit(ms, this.guiLeft + 78, this.guiTop + 27, 0, 0, 24, 24, 24, 24);
		}
		if (AdvanceCondition8Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/advance_8.png"));
			this.blit(ms, this.guiLeft + 78, this.guiTop + 27, 0, 0, 24, 24, 24, 24);
		}
		if (AdvanceCondition9Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/advance_9.png"));
			this.blit(ms, this.guiLeft + 78, this.guiTop + 27, 0, 0, 24, 24, 24, 24);
		}
		if (AdvanceCondition10Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/advance_10.png"));
			this.blit(ms, this.guiLeft + 78, this.guiTop + 27, 0, 0, 24, 24, 24, 24);
		}
		if (AdvanceCondition11Procedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/advance_11.png"));
			this.blit(ms, this.guiLeft + 78, this.guiTop + 27, 0, 0, 24, 24, 24, 24);
		}
		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/gui_button_field.png"));
		this.blit(ms, this.guiLeft + -24, this.guiTop + 8, 0, 0, 25, 25, 25, 25);
		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/gui_button_field.png"));
		this.blit(ms, this.guiLeft + -24, this.guiTop + 60, 0, 0, 25, 25, 25, 25);
		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/gui_button_field.png"));
		this.blit(ms, this.guiLeft + -24, this.guiTop + 34, 0, 0, 25, 25, 25, 25);
		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/gui_safety_open.png"));
		this.blit(ms, this.guiLeft + -19, this.guiTop + 12, 0, 0, 16, 16, 16, 16);
		if (SafetyConditionProcedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/gui_safety_close.png"));
			this.blit(ms, this.guiLeft + -19, this.guiTop + 12, 0, 0, 16, 16, 16, 16);
		}
		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/gui_redstone_off.png"));
		this.blit(ms, this.guiLeft + -19, this.guiTop + 38, 0, 0, 16, 16, 16, 16);
		if (RedstoneLowConditionProcedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/gui_redstone_low.png"));
			this.blit(ms, this.guiLeft + -19, this.guiTop + 38, 0, 0, 16, 16, 16, 16);
		}
		if (RedstoneHighConditionProcedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/gui_redstone_high.png"));
			this.blit(ms, this.guiLeft + -19, this.guiTop + 38, 0, 0, 16, 16, 16, 16);
		}
		if (InfoConditionProcedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world))) {
			Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/gui_info_field.png"));
			this.blit(ms, this.guiLeft + -107, this.guiTop + 60, 0, 0, 108, 105, 108, 105);
		}
		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("technical_engineering:textures/gui_info.png"));
		this.blit(ms, this.guiLeft + -20, this.guiTop + 64, 0, 0, 16, 16, 16, 16);
		RenderSystem.disableBlend();
	}

	@Override
	public boolean keyPressed(int key, int b, int c) {
		if (key == 256) {
			this.minecraft.player.closeScreen();
			return true;
		}
		return super.keyPressed(key, b, c);
	}

	@Override
	public void tick() {
		super.tick();
	}

	@Override
	protected void drawGuiContainerForegroundLayer(MatrixStack ms, int mouseX, int mouseY) {
		this.font.drawString(ms, "Crusher", 71, 7, -12829636);
		if (InfoConditionProcedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world)))
			this.font.drawString(ms, "Crush ores into", -99, 70, -12829636);
		if (InfoConditionProcedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world)))
			this.font.drawString(ms, "dusts.", -99, 79, -12829636);
		if (InfoConditionProcedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world)))
			this.font.drawString(ms, "Use 20FE a tick.", -99, 106, -12829636);
		if (InfoConditionProcedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world)))
			this.font.drawString(ms, "Make double ores!", -99, 93, -12829636);
		if (InfoConditionProcedure.executeProcedure(ImmutableMap.of("x", x, "y", y, "z", z, "world", world)))
			this.font.drawString(ms, "Buzzzzzz...", -99, 120, -12829636);
	}

	@Override
	public void onClose() {
		super.onClose();
		Minecraft.getInstance().keyboardListener.enableRepeatEvents(false);
	}

	@Override
	public void init(Minecraft minecraft, int width, int height) {
		super.init(minecraft, width, height);
		minecraft.keyboardListener.enableRepeatEvents(true);
	}
}
